package com.hnevc.acountms.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hnevc.acountms.R;
import com.hnevc.acountms.activity.AddInAccountActivity;
import com.hnevc.acountms.activity.FlagAddActivity;
import com.hnevc.acountms.activity.InaccountInfoActivity;
import com.hnevc.acountms.activity.ShowInfoActivity;
import com.hnevc.acountms.activity.SystemSetActivity;

import static android.content.ContentValues.TAG;

/**
 * Created by Administrator on 2017/9/28.
 */

public class PictureAdapter extends RecyclerView.Adapter<PictureAdapter.MyViewHolder> {
    private Context mContext;
    private int[] mImages;
    private String[] mTitles;

    public PictureAdapter(Context context, int[] images, String[] titles) {
        mContext = context;
        mImages = images;
        mTitles = titles;
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.list_item, parent, false);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.mImageView.setImageResource(mImages[position]);
        holder.mTextView.setText(mTitles[position]);

    }

    @Override
    public int getItemCount() {
        return mImages.length;
    }


    class MyViewHolder extends RecyclerView.ViewHolder {
        ImageView mImageView;
        TextView mTextView;

        public MyViewHolder(View itemView) {
            super(itemView);
            mImageView = (ImageView) itemView.findViewById(R.id.id_item_image);
            mTextView = (TextView) itemView.findViewById(R.id.id_tv_item_title);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int position = getAdapterPosition();
                    Log.e(TAG, "onClick: " + position);
                    switch (position) {
                        case 0: {
                            Intent intent = new Intent(mContext, AddInAccountActivity.class);
                            mContext.startActivity(intent);
                            break;
                        }
                        case 1:
                            break;
                        case 2:
                            break;
                        case 3: {
                            Intent intent = new Intent(mContext, InaccountInfoActivity.class);
                            mContext.startActivity(intent);
                            break;

                        }
                        case 4: {
                            ShowInfoActivity.startActivity(mContext);
                            break;
                        }
                        case 5:{
                            SystemSetActivity.actionStart(mContext);
                            break;
                        }
                        case 6:{
                            FlagAddActivity.actionStart(mContext);
                            break;
                        }
                    }

                }
            });
        }


    }
}
